package com.elbis.action.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import com.elbis.business.controller.StaticValuesBean;
import com.elbis.business.entity.locale.City;

@FacesConverter("cityConverter")
public class CityConverter implements Converter {

	private StaticValuesBean staticValues = null;

	@Override
	public Object getAsObject(FacesContext context, UIComponent component,
			String value) {
		if (value != null) {
			return staticValues.getCityByName(value);
		}
		return null;
	}

	@Override
	public String getAsString(FacesContext context, UIComponent component,
			Object value) {
		if (value != null && value instanceof City) {
			return ((City) value).getName();
		}
		return null;
	}

	public StaticValuesBean getStaticValues() {
		return staticValues;
	}

	public void setStaticValues(StaticValuesBean staticValues) {
		this.staticValues = staticValues;
	}

}
